const PREFIX = 'FRONT_';
/**
 * 存储localStorage
 */
export const setStore = (name, content) => {
	if (!name) return;
	if (!process.client) return;
	if (typeof content !== 'string') {
		content = JSON.stringify(content);
	}

	window.localStorage.setItem(PREFIX + name, content);
}

/**
 * 获取localStorage
 */
export const getStore = name => {
	if (!name) return;
	if (!process.client) return;
	let v = window.localStorage.getItem(PREFIX + name);
	if (v == null) {
		return "";
	}
	return v;
}

/**
 * 删除localStorage
 */
export const removeStore = name => {
	if (!name) return;
	if (!process.client) return;
	window.localStorage.removeItem(PREFIX + name);
}
/**
 * 删除全部前缀localStorage
 */
export const removeAllStore = () => {
	if (!process.client) return;
	Object.keys(window.localStorage).forEach(item => item.indexOf(PREFIX) !== -1 ? window.localStorage.removeItem(
		item) : '');
	Object.keys(window.localStorage).forEach(item => item.indexOf('TIM_') !== -1 ? window.localStorage.removeItem(
		item) : '');
	window.localStorage.removeItem('pgv_pri');
	window.localStorage.removeItem('loglevel');
}
